﻿// Copyright notices:
// ---
// Originally Written in 2012 by Christian Winnerlein  <codesinchaos@gmail.com>
// Rewritten Fall 2014 (for the Blake2s flavor instead of the Blake2b flavor)
//   by Dustin Sparks <sparkdustjoe@gmail.com>

// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.

// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
// ---
// Based on BlakeSharp
// by Dominik Reichl <dominik.reichl@t-online.de>
// Web: http://www.dominik-reichl.de/
// If you're using this class, it would be nice if you'd mention
// me somewhere in the documentation of your program, but it's
// not required.
// BLAKE was designed by Jean-Philippe Aumasson, Luca Henzen,
// Willi Meier and Raphael C.-W. Phan.
// BlakeSharp was derived from the reference C implementation.
// ---
// This implementation is based on: https://github.com/SparkDustJoe/miniLockManaged
// Reason:
// - Have a single nuget package for Blake2s
// - Added libsodium-net similar interface for the hash functions.
// <auto-generated />

using System;

namespace Blake2s
{
    public sealed class Blake2sConfig : ICloneable
    {
        public byte[] Personalization { get; set; }
        public byte[] Salt { get; set; }
        public byte[] Key { get; set; }
        public int OutputSizeInBytes { get; set; }
        public int OutputSizeInBits
        {
            get { return OutputSizeInBytes * 8; }
            set
            {
                if (value % 8 == 0)
                    throw new ArgumentException("Output size must be a multiple of 8 bits");
                OutputSizeInBytes = value / 8;
            }
        }

        public Blake2sConfig()
        {
            OutputSizeInBytes = 32;
        }

        public Blake2sConfig Clone()
        {
            var result = new Blake2sConfig();
            result.OutputSizeInBytes = OutputSizeInBytes;
            if (Key != null)
                result.Key = (byte[])Key.Clone();
            if (Personalization != null)
                result.Personalization = (byte[])Personalization.Clone();
            if (Salt != null)
                result.Salt = (byte[])Salt.Clone();
            return result;
        }

        object ICloneable.Clone()
        {
            return Clone();
        }
    }
}
